#include "watcherController.h"
#include "view/watcherView.h"
#include "view/camera/first_person_camera.h"

WatcherController::WatcherController(View* view,Model* model)  : SceneController(view,model) {
}

WatcherController::~WatcherController(){

}

void WatcherController::keyboard(unsigned char key,float x ,float y){
	SceneController::keyboard(key,x,y);

	SceneModel& smodel = dynamic_cast<SceneModel&>(*model);
	SceneView& sview = dynamic_cast<SceneView&>(*this->view);
	FirstPersonCamera& camera = dynamic_cast<FirstPersonCamera&>(sview.getCamera());

	camera.moveTo(smodel.getWatcher().getWatcherPosition());

	switch(key){
		case 'w':
			camera.moveAhead(-0.5f);
			break;
		case 's':
			camera.moveAhead(0.5f);
			break;
		case 'a':
			camera.strafe(0.05f);
			break;
		case 'd':
			camera.strafe(-0.05f);
			break;
	}

	smodel.getWatcher().moveWatcherTo(camera.getEye().x1,camera.getEye().x2);
}

void WatcherController::redisplay(){
	SceneController::redisplay();

	SceneModel& smodel = dynamic_cast<SceneModel&>(*model);
	SceneView& sview = dynamic_cast<SceneView&>(*this->view);

	std::ostringstream stream;
	Point pos = smodel.getWatcher().getWatcherPosition();
	stream << "x: " << pos.x1 << " y: " << pos.x2 << " z: " << pos.x3 << std::endl;
	sview.renderText(stream.str(),0.65,0.70);
}
